|
|
|
|
|
|
|
This is slow enough that ray tracing a complicated scene can take hours or even days. This glacial speed is the one major drawback to ray tracing. While it provides many powerful features, such as hidden surface removal, shadows, and a complete lighting model, ray tracing takes far longer than the less realistic Depth-Sort algorithm.You can do a few things to make the process faster. Two of the simpler techniques are using bounding volumes and scanline culling. These techniques are described in the following sections. |
|
|
|
|
|
|
|
|
In a complicated scene, you may be able to use the arrangement of the objects to avoid calculating some ray-object intersections. You may be able to group several nearby objects and surround them with a bounding volume like a sphere. If a ray does not intersect the sphere, you know that it does not intersect any of the objects within the sphere, so you do not need to test for intersections with each of the objects separately. |
|
|
|
|
|
|
|
|
This method is most useful when the scene contains a large number of small objects. In particular, if the scene contains a solid object made up of many polygonal faces, bounding volumes may greatly reduce the number of intersections you need to compute. If a ray does not intersect the bounding volume, you do not need to intersect it with each of the polygonal faces. |
|
|
|
|
|
|
|
|
Even for relatively simple objects, you can sometimes improve performance by using bounding volumes. For instance, even though a cube is a fairly simple object, it takes less time to find the intersection between a ray and a sphere bounding the cube than it does to test each of the cube's six faces separately. If the ray does not intersect the bounding sphere, you do not need to test the faces individually. |
|
|
|
|
|
|
|
|
On the other hand, if a ray does intersect a bounding volume, you still need to test the objects inside. If a bounding volume occupies most of the scene space, most of the rays intersect it. Then you need to test the objects inside almost all the time. In that case, the bounding volume test is extra work that does not save you much time, so you are better off without it. |
|
|
|
|
|
|
|
|
For many objects, spheres make convenient bounding volumes, but for some objects, other volumes are more appropriate. For example, suppose a scene contains a collection of squares arranged in a rectangle in a plane. It would make sense to use a rectangle that contains the squares as a bounding volume. Before checking the squares to see if a ray intersects them, you could see if it intersects the bounding rectangle. |
|
|
|
|
|
|
|
|
In this case the bounding rectangle might occupy much of the resulting image, so you will have gained only a small improvement. You can take advantage of the special geometry of the situation to gain a much greater improvement. If the squares do not overlap, a ray can intersect at most one of them at a time. While testing the squares, if you find one that the ray intersects, you do not need to check any of the others. With a little extra work, you can even use the point of intersection between the ray and bounding rectangle to directly compute which of the squares contains the point. The RayCheckerboard class described later in this chapter uses that method to treat a collection of squares as a single object. |
|
|
|
|
|